import { userInfoAPI } from '@/api/user'
export default {
  namespaced: true,
  state () {
    return {
      // 从本地取出来--本地没用则给空对象
      tokenObj: {},
      userInfo: {}
    }
  },
  mutations: {
    setToken (state, obj) {
      state.tokenObj = obj
      // token 持久化----存到本地
    //   localStorage.setItem('hmtt100', JSON.stringify(obj))
    },
    setUserInfo (state, obj) {
      state.userInfo = obj
    }
  },
  actions: {
    async reqSetInfo (context) {
      if (!context.state.userInfo.name) {
        const res = await userInfoAPI()
        // console.log('res...', res)
        context.commit('setUserInfo', res.data)
      }
    }
  }
}
